package com.winz.cultureapp.adapter.xrcv;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.mine.xrecyclerview.rcvadapter.BaseRcvAdapter;
import com.mine.xrecyclerview.rcvadapter.ViewHolder;
import com.winz.cultureapp.R;
import com.winz.cultureapp.entity.PersonItem2ListBean;

import java.util.List;
import java.util.Random;

/**
 * 个人记录--活动预定
 */

public class PersonalItem2Adapter extends BaseRcvAdapter<PersonItem2ListBean.DataBean.ListBean> {

    private OnCancledListener listener;

    public PersonalItem2Adapter(Context context, List<PersonItem2ListBean.DataBean.ListBean> datas, int... resid) {
        super(context, datas, resid);
    }

    @Override
    public void convert(ViewHolder holder, PersonItem2ListBean.DataBean.ListBean data, int itemViewType) {

    }


    @Override
    public void convert(int position, ViewHolder holder, PersonItem2ListBean.DataBean.ListBean listBean, int itemViewType) {
        super.convert(position, holder, listBean, itemViewType);
        if (itemViewType != -1){

            holder.setText(R.id.tv_location,listBean.activityName)
                    .setText(R.id.tv_no,"订单号："+listBean.orderNumber)
                    .setText(R.id.tv_adress,"地址：" + listBean.address)
                    .setText(R.id.tv_seat,"座位：" + (TextUtils.isEmpty(listBean.seatDesc)?"无":listBean.seatDesc))
                    .setText(R.id.tv_type,listBean.useStatus == 0?"未使用":listBean.useStatus == 1?"已使用":"已过期")
                    .setBackgroundRes(R.id.tv_type,listBean.useStatus == 0?R.drawable.corner_all_13_green:listBean.useStatus == 1?R.drawable.corner_all_13_blue:R.drawable.corner_all_13_red)
                    .setTextColor(R.id.tv_type,mContext.getResources().getColor(listBean.useStatus == 0?R.color.base_color:listBean.useStatus == 1?R.color.dodgerblue:R.color.icon_red))
                    .setText(R.id.tv_price,"￥ " + listBean.seatMoney);

 /*
                取消预定
             */
            holder.getView(R.id.tv_cancle).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listener != null) {
                        listener.onCancle(position);
                    }
                }
            });

            Glide.with(mContext)
                    .load(listBean.imageUrl)
                    .error(R.drawable.pic_default)
                    .into((ImageView) holder.getView(R.id.iv_pic));
            if (position == 0){
                holder.getView(R.id.view_header).setVisibility(View.VISIBLE);
            }else{
                holder.getView(R.id.view_header).setVisibility(View.GONE);
            }
        }


    }

    public interface OnCancledListener{
        void onCancle(int position);
    }

    public void setOnCancleListener(OnCancledListener listener){
        this.listener = listener;
    }
}
